package com.example.ware.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.common.utils.PageUtils;
import com.common.utils.Query;

import com.example.ware.dao.WmsPurchaseDetailDao;
import com.example.ware.entity.WmsPurchaseDetailEntity;
import com.example.ware.service.WmsPurchaseDetailService;
import org.springframework.util.StringUtils;


@Service("wmsPurchaseDetailService")
public class WmsPurchaseDetailServiceImpl extends ServiceImpl<WmsPurchaseDetailDao, WmsPurchaseDetailEntity> implements WmsPurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<WmsPurchaseDetailEntity> page = this.page(
                new Query<WmsPurchaseDetailEntity>().getPage(params),
                new QueryWrapper<WmsPurchaseDetailEntity>()
        );

        return new PageUtils(page);
    }


    @Override
    public PageUtils queryPageByKey(Map<String, Object> params) {
        String wareid = (String) params.get("wareId");
        String status = (String) params.get("status");
        String key = (String) params.get("key");
        QueryWrapper<WmsPurchaseDetailEntity> wrapper = new QueryWrapper<>();
        if (wareid != null && wareid.length() > 0) {
            wrapper.eq("ware_id", Long.parseLong(wareid));
        }
        if (!StringUtils.isEmpty(status)) {
            wrapper.eq("status", Long.parseLong(status));
        }
        if (!StringUtils.isEmpty(key)) {
            wrapper = wrapper.like("sku_num", key).or().like("sku_price", key).or().eq("sku_id", key);
        }

        IPage<WmsPurchaseDetailEntity> page = this.page(
                new Query<WmsPurchaseDetailEntity>().getPage(params),
                wrapper
        );
        return new PageUtils(page);
    }

    @Override
    public List<WmsPurchaseDetailEntity> listDetailByPurchaseId(Long id) {

        List<WmsPurchaseDetailEntity> purchaseId = this.list(new QueryWrapper<WmsPurchaseDetailEntity>().eq("purchase_id", id));

        return purchaseId;
    }
}